package butines.core;


public class ImageSheet {

	private Image imageSource;
	private Image[][] images;

	private int imageWidth;
	private int imageHeight;
	private int numImageX;
	private int numImageY;
	private int numImage;
	
	public ImageSheet(Image imageSource, int imageWidth, int imageHeight) {
		this.imageSource = imageSource;
		this.imageWidth = imageWidth;
		this.imageHeight = imageHeight;
		
		numImageX = imageSource.getImageWidth() / imageWidth; 
		numImageY = imageSource.getImageHeight() / imageHeight;
		
		numImage = numImageY * numImageX;
		images = new Image[numImageY][numImageX];
		for (int y = 0; y < numImageY; y++) {
			for (int x = 0; x < numImageX; x++) {
				images[y][x] = imageSource.getSubImage(x * imageWidth, y * imageHeight, imageWidth, imageHeight);
			}
		}
		
	}
		
	public Image getImage(int x, int y) {
		return images[y][x];
	}
	
	
	public Image getImage(int index) {
		int x = index % numImageX;
		int y = index / numImageX;
		return images[y][x];
	}

	public Image getImageSource() {
		return imageSource;
	}

	public int getImageWidth() {
		return imageWidth;
	}

	public int getImageHeight() {
		return imageHeight;
	}

	public int getNumImageX() {
		return numImageX;
	}

	public int getNumImageY() {
		return numImageY;
	}
	
	public int getNumImage() {
		return numImage;
	}
	
}
